# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
using("SideMenu_Open.air")
import SideMenu_Open
        
class SideMenu_Certification(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))

        certName = "兔八哥"
        certID = "542546199009097456"

        if "name" in args:
            certName = args["name"]
        
        if "id" in args:
            certID = args["id"]

        # 打开左侧菜单
        isOpenSideMenu = SideMenu_Open.runTest({})
        if not isOpenSideMenu:
            return False

        # 获取左侧菜单节点
        bottomPanel = poco("bottom_panel")
        if not bottomPanel.exists():
            return False

        # 获取实名认证按钮，并点击
        btnCert = bottomPanel.offspring("identity_btn")
        if not btnCert.exists():
            # 实名按钮不存在，说明已经实名认证过了
            txtIdentity = bottomPanel.offspring("identity_text")
            if txtIdentity.exists():
                assert_equal(txtIdentity.get_text(), "已认证", "已经实名认证成功")
                poco.click([0.7, 0.5])
            return True
        # 点击实名认证按钮
        self.clickButton(btnCert)
        # 等待实名认证弹框
        try:
            poco("IdentityLayer").wait_for_appearance()
        except:
            assert(0, 1, "实名认证弹框显示正常")
            return False
        # 获取实名认证弹框
        identityLayer = poco("IdentityLayer")
        # 输入姓名
        txtName = identityLayer.offspring("name_textfield")
        self.clickButton(txtName)
        text(certName)
        # 输入身份证号码
        txtID = identityLayer.offspring("id_textfield")
        self.clickButton(txtID)
        text(certID)
        # 提交实名信息
        btnSubmit = identityLayer.offspring("submit_btn")
        self.clickButton(btnSubmit)
        # 获取成功弹框
        successPanel = identityLayer.offspring("success_panel")
        if successPanel.exists():
            assert_equal(successPanel.exists(), True, "成功进行实名认证")
            btnSuccess = successPanel.offspring("success_btn")
            self.clickButton(btnSuccess)
        else:
            # 获取提示信息
            toastView = poco("ToastView")        
            if toastView.exists():
                txtContent = toastView.offspring("text_content").get_text()
                assert_equal(txtContent, "请输入正确的身份信息", "认证信息有误[%s,%s]" % (certName, certId))

        poco.click([0.7, 0.5])

        return True
        
_instance = SideMenu_Certification()
runTest = _instance.runTest